<?php

namespace App\Http\Requests;

use App\Traits\ApiResponse;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Exceptions\HttpResponseException;

class BaseRequests extends FormRequest
{
    use ApiResponse;
    protected $route_name;

    public function __construct()
    {
        parent::__construct();
        $this->route_name = Route::currentRouteName();
    }

    public function authorize()
    {
        return true;
    }

    public function failedValidation($validator)
    {

        $error= $validator->errors()->all();

        throw new HttpResponseException($this->fail($error[0]));
    }
}